<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style>
    html,
    body,
    #container {
      width: 100%;
      height: 100%;
    }
    </style>
    <title>折线的编辑</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <script src="https://webapi.amap.com/maps?v=2.0&key=您申请的key值&plugin=AMap.PolylineEditor"></script>
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
</head>
<body>
<div id="container"></div>
<div class="input-card" style="width: 120px">
   <button class="btn" onclick="editPolyline1()" style="margin-bottom: 5px">编辑Polyline1</button> 
   <button class="btn" onclick="editPolyline2()" style="margin-bottom: 5px">编辑Polyline2</button> 
   <button class="btn" onclick="createPolyline()" style="margin-bottom: 5px">新建Polyline</button>
   <button class="btn" onclick="polyEditor.close()">结束编辑</button> 
</div>
<script type="text/javascript">
    var map = new AMap.Map("container", {
      center: [116.400274, 39.905812],
      zoom: 14
    });

    var path = [
      [116.403322, 39.920255],
      [116.410703, 39.897555],
      [116.402292, 39.892353],
      [116.389846, 39.891365]
    ]
    var path1 = [
      [116.453322, 39.920255],
      [116.460703, 39.897555],
      [116.452292, 39.892353],
      [116.439846, 39.891365]
    ]

    var polyline1 = new AMap.Polyline({
      path: path,
      strokeColor: "#FF33FF",
      strokeWeight: 6,
      strokeOpacity: 0.9,
      zIndex: 50,
      bubble: true,
    })
    var polyline2 = new AMap.Polyline({
      path: path1,
      strokeColor: "green",
      strokeWeight: 6,
      strokeOpacity: 0.9,
      zIndex: 50,
      bubble: true,

    })

    map.add([polyline1, polyline2])

    // 缩放地图到合适的视野级别
    map.setFitView()
    var polyEditor;
      // var polyEditor = new AMap.PolyEditor(map, polygon)
      // polyEditor = new AMap.PolygonEditor(map)
    polyEditor = new AMap.PolylineEditor(map, polyline1);
    polyEditor.setTarget(polyline1);
    polyEditor.open();
    function editPolyline1(){
        polyEditor.setTarget(polyline1);
        polyEditor.open();
    }
    function editPolyline2(){
        polyEditor.setTarget(polyline2);
        polyEditor.open();
    }
  function printPolylinePath(polyline) {
    var path = polyline.getPath();
    console.log("当前折线的经纬度坐标：", path);
}
    function createPolyline(){
        polyEditor.setTarget();
        polyEditor.open();
    }
  </script>
</body>
</html>